<?php

(!defined('IN_TOA') || !defined('IN_ADMIN')) && exit('Access Denied!');
/*
	[天生创想] (C)2008-2011 515158 Inc.
	This is NOT a freeware, use is subject to license terms
    URL:http://www.515158.com/
*/
if ($_GET[type]=='1')
{
$keynews='news_new_type';
}elseif($_GET[type]=='2')
{
$keynews='news_pic_new_type';
}elseif($_GET[type]=='3')
{
$keynews='news_cement_type';
}elseif($_GET[type]=='4')
{
$keynews='news_notice_type';
}elseif($_GET[type]=='5')
{
$keynews='news_chronicle_type';
}elseif($_GET[type]=='6')
{
$keynews='news_periodical_type';
}

get_config_keytable($keynews);

empty($do) && $do = 'list';

$message = array(
	1 => '成功更新分类设置。',
	2 => '成功删除分类设置。',
);

if ($do == 'list') {
	$type=$_GET[type];
	$result = array();
	$sql = "SELECT * FROM ".DB_TABLEPRE."news_type where ntype='".$type."' ORDER BY nid asc";
	$query = $db->query($sql);
	while ($row = $db->fetch_array($query)) {
		//$row['count'] = $db->result("SELECT COUNT(*) AS num FROM ".DB_TABLEPRE."office_type WHERE oid = '$row[oid]'");
		$result[] = $row;
	}
	include_once('template/news_type.php');

} elseif ($do == 'update') {
	$type=$_GET[type];
	$officetype = array();
	$officetype['ntitle'] = check_str(getGP('newname','P'));
	$officetype['ntype'] = $type;
	$officetype['uid'] = $_USER->id;
	$officetype['ndate'] = get_date('Y-m-d H:i:s',PHP_TIME);
	if (!empty($officetype['ntitle'])) {
		insert_db('news_type', $officetype);
	}
	$oname = getGP('name','P','array');
	foreach ($oname as $key => $val) {
		$key = (int)$key;
		$db->query("UPDATE ".DB_TABLEPRE."news_type SET ntitle = '$val' WHERE nid = '$key'");
	}
	goto_page('admin.php?ac=news_type&fileurl=news&type='.$type.'&message=1&muid='.$_GET[muid].'');

} elseif ($do == 'delete') {
    $type=$_GET[type];
	$id = getGP('id','G','int');
	$db->query("DELETE FROM ".DB_TABLEPRE."news_type WHERE nid = '$id'");
	goto_page('admin.php?ac=news_type&fileurl=news&type='.$type.'&message=2&muid='.$_GET[muid].'');
}

?>